3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
QuickDraw 3D RAVE supports draw context caching, a technique that allows you to improve rendering performance when a large number of the objects in a scene don't change from frame to frame. A draw context cache is simply a draw context that contains an image and is designated as the initial context in a call to QARenderStart . The contents of that context are drawn into the destination draw context before any other objects.
To create a draw context cache, you first create a draw context by calling the QADrawContextNew function, where the flags parameter has the QAContext_Cache flag set. Then you draw the unchanging objects into the draw context cache. For example, suppose that you want to draw a series of frames in which two triangles remain constant from frame to frame but a third triangle changes every frame. Listing 9 shows how to do this.
Listing 9 Creating and using a draw context cache
TQAVGouraud tri1[3], tri2[3], tri3[3];
TQADrawContext *myCache, *myDest;
/*Create draw context cache and destination draw context.*/
QADrawContextNew(myDev, rect, NULL, myEng, QAContext_Cache, &myCache);
QADrawContextNew(myDev, rect, NULL, myEng, QAContext_DoubleBuffer, &myDest);
/*Set up the image in the cache context.*/
QARenderStart(myCache, NULL, NULL);
QADrawTriGouraud(myCache, &tri1[0], &tri1[1], &tri1[2], kQATriFlags_None);
QADrawTriGouraud(myCache, &tri2[0], &tri2[1], &tri2[2], kQATriFlags_None);
QARenderEnd(myCache, NULL);
/*Render frames using the cache and moving tri3 only.*/
while (gStillMovingTriangle3) {
MyMoveTri(tri3);
QARenderStart(myDest, NULL, myCache);
QADrawTriGouraud(myDest, &tri3[0], &tri3[1], &tri3[2], kQATriFlags_None);
QARenderEnd(myDest, NULL);
}
Not all drawing engines support draw context caching. If a drawing engine does not support caching, it should return the value NULL whenever you pass the QAContext_Cache flag to QADrawContextNew .
All draw context caches must be single buffered, and they must be created using the same device and rectangle as the destination draw contexts with which they will be used.
Once you've created a draw context cache (by setting the QAContext_Cache flag when calling QADrawContextNew ), you cannot use that draw context as a non-cached draw context. Objects rendered into a draw context cache never appear on a device (not even on a memory device). The only way to view objects rendered into a draw context cache is to use that cache to initialize a non-cached draw context, as illustrated in Listing 9 . You can, however, use a draw context cache to initialize another draw context cache. Moreover, you can initialize a draw context cache with itself in order to add more objects to an existing draw context cache.
Previous | QD3D Book | Overview | Chapter Contents | Next |